import { BaseService } from '@/core/base.service';
import { Injectable } from '@nestjs/common';
import { Prisma, Setting } from '@prisma/client';

@Injectable()
export class SettingService extends BaseService {
  async getDefault() {
    const data = await this.prisma.setting.findUnique({ where: { id: 1 } });
    return {
      ...data,
      fee: Number(data.fee),
      withdrawFee: Number(data.withdrawFee),
    };
  }

  async update(data: Prisma.SettingUpdateInput): Promise<Setting> {
    return this.prisma.setting.update({
      where: {
        id: 1,
      },
      data,
    });
  }

  async getAppVersion() {
    const data = await this.prisma.setting.findUnique({ where: { id: 1 } });
    return {
      version: data.androidVersion,
      url: data.androidUrl,
      now_url: data.androidUploadUrl,
      silent: 0,
      force: 1,
      node: data.androidUploadNote,
    };
  }
}
